%%%-------------------------------------------------------------------
%%% @author Administrator
%%% @copyright (C) 2023, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 13. 4月 2023 19:15
%%%-------------------------------------------------------------------
-module(sc_event).
-export([start_link/0,
  add_handler/2,
  delete_handler/2,
  lookup/1,
  create/2,
  replace/2,
  delete/1]).
-define(SERVER, ?MODULE).
start_link() -> % ❶ (以下2行) 隐藏gen_event启动函数
  gen_event:start_link({local, ?SERVER}).
add_handler(Handler, Args) -> % ❷ (以下4行) 隐藏gen_event处理器注册逻辑
  gen_event:add_handler(?SERVER, Handler, Args).
delete_handler(Handler, Args) ->
  gen_event:delete_handler(?SERVER, Handler, Args).
lookup(Key) -> % ❸ (以下8行) API函数
  gen_event:notify(?SERVER, {lookup, Key}).
create(Key, Value) ->
  gen_event:notify(?SERVER, {create, {Key, Value}}).
replace(Key, Value) ->
  gen_event:notify(?SERVER, {replace, {Key, Value}}).
delete(Key) ->
  gen_event:notify(?SERVER, {delete, Key}).
